<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=6.3.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32*32.ico?v=6.3.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16*16.ico?v=6.3.0">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=6.3.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '6.3.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="Ignite是什么  一个以内存为中心的分布式数据库、缓存和处理平台，可以在PB级数据中，以内存级的速度进行事务性、分析性以及流式负载的处理。 支持磁盘、第三方存储持久化数据。 在内存和磁盘上是同时支持ACID的，是一个强一致的系统，Ignite可以在整个拓扑的多台服务器上保持事务。 完整的SQL和键值支持。 数据的并置计算。 是一个弹性的、可水平扩展的分布式系统，它支持按需地添加和删除节点，Ig">
<meta name="keywords" content="Java,Ignite,分布式">
<meta property="og:type" content="article">
<meta property="og:title" content="ignite实践踩坑录(1) 简介与持久化">
<meta property="og:url" content="https://gitee.com/hhbbz/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/index.html">
<meta property="og:site_name" content="hhbbz-Blog">
<meta property="og:description" content="Ignite是什么  一个以内存为中心的分布式数据库、缓存和处理平台，可以在PB级数据中，以内存级的速度进行事务性、分析性以及流式负载的处理。 支持磁盘、第三方存储持久化数据。 在内存和磁盘上是同时支持ACID的，是一个强一致的系统，Ignite可以在整个拓扑的多台服务器上保持事务。 完整的SQL和键值支持。 数据的并置计算。 是一个弹性的、可水平扩展的分布式系统，它支持按需地添加和删除节点，Ig">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://gitee.com/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/002.png">
<meta property="og:updated_time" content="2020-04-22T01:56:08.803Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ignite实践踩坑录(1) 简介与持久化">
<meta name="twitter:description" content="Ignite是什么  一个以内存为中心的分布式数据库、缓存和处理平台，可以在PB级数据中，以内存级的速度进行事务性、分析性以及流式负载的处理。 支持磁盘、第三方存储持久化数据。 在内存和磁盘上是同时支持ACID的，是一个强一致的系统，Ignite可以在整个拓扑的多台服务器上保持事务。 完整的SQL和键值支持。 数据的并置计算。 是一个弹性的、可水平扩展的分布式系统，它支持按需地添加和删除节点，Ig">
<meta name="twitter:image" content="https://gitee.com/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/002.png">






  <link rel="canonical" href="https://gitee.com/hhbbz/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>ignite实践踩坑录(1) 简介与持久化 | hhbbz-Blog</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">hhbbz-Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">hhbbz</h1>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/blog/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-about">
    <a href="/blog/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/blog/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/blog/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/blog/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/hhbbz/blog/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="hhbbz">
      <meta itemprop="description" content="摘抄和记录的地方">
      <meta itemprop="image" content="/blog/images/TOM.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="hhbbz-Blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">ignite实践踩坑录(1) 简介与持久化
              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-05-19 14:07:35" itemprop="dateCreated datePublished" datetime="2019-05-19T14:07:35+08:00">2019-05-19</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-04-22 09:56:08" itemprop="dateModified" datetime="2020-04-22T09:56:08+08:00">2020-04-22</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/后端/" itemprop="url" rel="index"><span itemprop="name">后端</span></a></span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/#comments" itemprop="discussionUrl">
                  <span class="post-meta-item-text">评论数：</span> <span class="post-comments-count valine-comment-count" data-xid="/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="post-meta-item-icon"
            >
            <i class="fa fa-eye"></i>
             阅读次数： 
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1>Ignite是什么</h1>
<ol>
<li>一个以内存为中心的分布式数据库、缓存和处理平台，可以在PB级数据中，以内存级的速度进行事务性、分析性以及流式负载的处理。</li>
<li>支持磁盘、第三方存储持久化数据。</li>
<li>在内存和磁盘上是同时支持ACID的，是一个强一致的系统，Ignite可以在整个拓扑的多台服务器上保持事务。</li>
<li>完整的SQL和键值支持。</li>
<li>数据的并置计算。</li>
<li>是一个弹性的、可水平扩展的分布式系统，它支持按需地添加和删除节点，Ignite还可以存储数据的多个副本，这样可以使集群从部分故障中恢复。</li>
</ol>
<h1>ignite服务端和客户端</h1>
<p>Ignite有一个可选的概念，就是客户端节点和服务端节点，服务端节点参与缓存、计算执行、流式处理等等，而原生的客户端节点提供了远程连接服务端的能力。Ignite原生客户端可以使用完整的Ignite API集合，包括近缓存、事务、计算、流、服务等等。
所有的Ignite节点默认都是以服务端模式启动的，客户端模式需要显式地启用。
可以通过IgniteConfiguration.setClientMode(...)属性配置一个节点，或者为客户端，或者为服务端。
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">IgniteConfiguration cfg = <span class="keyword">new</span> IgniteConfiguration();</span><br><span class="line"><span class="comment">// Enable client mode.</span></span><br><span class="line">cfg.setClientMode(<span class="keyword">true</span>);</span><br><span class="line"><span class="comment">// Start Ignite in client mode.</span></span><br><span class="line">Ignite ignite = Ignition.start(cfg);</span><br></pre></td></tr></table></figure></p>
<p>Ignite的唯一特点是所有节点都是平等的。没有master节点或者server节点，也没有worker节点或者client节点，按照Ignite的观点所有节点都是平等的。但是，可以将节点配置成主节点，工作节点，或者客户端以及数据节点</p>
<h1>用Java来实现第一个Ignite应用</h1>
<p>如果不需要对IgniteConfiguration进行设置的话，我们直接以默认的参数进行启动就行，也就是一行代码：</p>
<p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Ignite ignite = Ignition.start();</span><br></pre></td></tr></table></figure></p>
<p>这样就会以服务端节点的形式去启动一个ignite节点，然后加入到集群中。</p>
<blockquote>
<p>第一坑：如果以客户端/瘦客户端形式去启动，会无法根据业务去动态构建缓存，并且会因为ignite服务端节点中没有我们应用的代码，然后因为业务的配置出现classNotFoundException，所以这里我采用在应用中启动ignite服务端节点的做法。</p>
</blockquote>
<p>然后我们需要对这个ignite节点进行构建缓存,来进行缓存操作。</p>
<p>Person.class</p>
<p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Getter</span></span><br><span class="line"><span class="meta">@Setter</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Person</span></span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//构造cacheConfig,可根据业务需要去动态进行构建</span></span><br><span class="line">CacheConfiguration ccf = <span class="keyword">new</span> CacheConfiguration();</span><br><span class="line"><span class="comment">//注意这里最好设置一个统一的schema</span></span><br><span class="line">ccf.setSqlSchema(<span class="string">"public"</span>);</span><br><span class="line">ccf.setName(<span class="string">"cacheName"</span>);</span><br><span class="line">ccf.setCacheMode(PARTITIONED);</span><br><span class="line">ccf.setAtomicityMode(CacheAtomicityMode.ATOMIC);</span><br><span class="line">ccf.setBackups(<span class="number">1</span>);</span><br><span class="line">ignite.getOrCreateCache(ccf)</span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>第二坑：如果不开启第三方持久化，并且没有配置QueryEntity的话，ignite不会进行自动建sql表，从而也就支持不了sql查询。
如果开启持久化的话，最好给一个默认的schema去让ignite建表，如图：</p>
</blockquote>
<p><img src="/blog/2019/05/19/Ignite踩坑录-1-简介与持久化/002.png" title="图片"></p>
<blockquote>
<p>第三坑：缓存配置一旦在集群中构建，便无法对其进行更新，如果确实有更新缓存配置的需要，只能通过destoryCache(),再createCache()的方法实现。</p>
</blockquote>
<p>下面列举构建一个开启第三方持久化的缓存配置例子：</p>
<p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">        <span class="comment">//构造cacheConfig</span></span><br><span class="line">        CacheConfiguration ccf = <span class="keyword">new</span> CacheConfiguration();</span><br><span class="line">        ccf.setSqlSchema(<span class="string">"public"</span>);</span><br><span class="line">        ccf.setName(<span class="string">"person"</span>);</span><br><span class="line">        ccf.setCacheMode(PARTITIONED);</span><br><span class="line">        ccf.setAtomicityMode(CacheAtomicityMode.ATOMIC);</span><br><span class="line">       ccf.setWriteBehindEnabled(<span class="keyword">true</span>);</span><br><span class="line">       <span class="comment">// 持久化后写每批次写入数量</span></span><br><span class="line">       ccf.setWriteBehindBatchSize(<span class="number">10</span>);</span><br><span class="line">       <span class="comment">//触发持久化后写的新增数据数量</span></span><br><span class="line">       ccf.setWriteBehindFlushSize(<span class="number">10</span>);</span><br><span class="line">       <span class="comment">//持久化后写刷新频率，即每过多少毫秒就持久化一次</span></span><br><span class="line">       ccf.setWriteBehindFlushFrequency(<span class="number">10000</span>);</span><br><span class="line">       <span class="comment">//持久化后写使用线程数量</span></span><br><span class="line">       ccf.setWriteBehindFlushThreadCount(<span class="number">10</span>);</span><br><span class="line">       ccf.setReadThrough(<span class="keyword">true</span>);</span><br><span class="line">       ccf.setWriteThrough(<span class="keyword">true</span>);</span><br><span class="line">       <span class="comment">//构造持久化类</span></span><br><span class="line">       CacheJdbcPojoStoreFactory storeFactory = <span class="keyword">new</span> CacheJdbcPojoStoreFactory();</span><br><span class="line">       storeFactory.setDataSource(<span class="keyword">this</span>.dataSource);</span><br><span class="line">       storeFactory.setDialect(<span class="keyword">new</span> BasicJdbcDialect());</span><br><span class="line"></span><br><span class="line">       LinkedHashMap&lt;String,String&gt; fieldMap = <span class="keyword">new</span> LinkedHashMap&lt;&gt;();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//构造字段列表</span></span><br><span class="line">       JdbcTypeField[] jdbcTypeFields = <span class="keyword">new</span> JdbcTypeField[<span class="number">10</span>];</span><br><span class="line"></span><br><span class="line">       <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>;i&lt;jdbcTypeFields.length;i++)&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">           <span class="comment">//注意字段不要java的date类型，否则存不上数据库</span></span><br><span class="line">            <span class="comment">//4是数据库字段类型的编码</span></span><br><span class="line">           jdbcTypeFields[i] = <span class="keyword">new</span> JdbcTypeField(<span class="number">4</span></span><br><span class="line">                   ,<span class="string">"fieldName"</span></span><br><span class="line">                   ,Integer.class</span><br><span class="line">                   ,<span class="string">"fieldName"</span>);</span><br><span class="line">           fieldMap.put(<span class="string">"fieldName"</span>,<span class="string">"Integer"</span>);</span><br><span class="line">       &#125;</span><br><span class="line"><span class="comment">//</span></span><br><span class="line">       <span class="comment">//构造jdbc字段映射</span></span><br><span class="line">       JdbcType jdbcType = <span class="keyword">new</span> JdbcType();</span><br><span class="line">       jdbcType.setCacheName(<span class="string">"person"</span>);</span><br><span class="line">       jdbcType.setKeyType(Integer.class);</span><br><span class="line">       jdbcType.setValueType(Person.class);</span><br><span class="line"><span class="comment">//        jdbcType.setDatabaseSchema(SQL_SCHEMA);</span></span><br><span class="line">       jdbcType.setDatabaseTable(<span class="string">"person"</span>);</span><br><span class="line">       jdbcType.setKeyFields(<span class="keyword">new</span> JdbcTypeField(<span class="number">4</span></span><br><span class="line">                   ,<span class="string">"fieldName"</span></span><br><span class="line">                   ,Integer.class</span><br><span class="line">                   ,<span class="string">"fieldName"</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">       jdbcType.setValueFields(jdbcTypeFields);</span><br><span class="line">       storeFactory.setTypes(jdbcType);</span><br><span class="line">        ccf.setBackups(<span class="number">1</span>);</span><br><span class="line">       ccf.setCacheStoreFactory(storeFactory);</span><br><span class="line">        <span class="comment">//会在ignite自动建表，并对持久化支持</span></span><br><span class="line">       QueryEntity queryEntity = <span class="keyword">new</span> QueryEntity();</span><br><span class="line">       queryEntity.setTableName(tableName);</span><br><span class="line">       queryEntity.setKeyType(<span class="string">"java.lang.Integer"</span>);</span><br><span class="line">       queryEntity.setValueType(<span class="string">"model.person"</span>);</span><br><span class="line">       queryEntity.setKeyFieldName(<span class="string">"id"</span>);</span><br><span class="line">       queryEntity.setKeyFields(Collections.singleton(<span class="string">"id"</span>));</span><br><span class="line">       queryEntity.setFields(fieldMap);</span><br><span class="line">       ccf.setQueryEntities(Collections.singleton(queryEntity));</span><br><span class="line">       ignite.getOrCreateCache(ccf);</span><br></pre></td></tr></table></figure></p>
<p>然后就可以使用构建的缓存进行操作啦</p>
<p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//执行select语句查询并获取返回结果</span></span><br><span class="line">Map&lt;String, Object&gt; result = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line"><span class="comment">// Getting a reference to an underlying cache created for table.</span></span><br><span class="line">IgniteCache&lt;Integer, Person&gt; cache = igniteEngine.getOrCreateCacheByCacheName(<span class="string">"person"</span>);</span><br><span class="line"><span class="comment">// Querying data from the cluster using a distributed JOIN.</span></span><br><span class="line">FieldsQueryCursor&lt;List&lt;?&gt;&gt; cursor = cache.query(<span class="keyword">new</span> SqlFieldsQuery(<span class="string">"select * from person"</span>).setSchema(<span class="string">"public"</span>));</span><br><span class="line">Iterator&lt;List&lt;?&gt;&gt; iterator = cursor.iterator();</span><br><span class="line"><span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">    List&lt;?&gt; row = iterator.next();</span><br><span class="line">    <span class="keyword">int</span> i = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (; i &lt; cursor.getColumnsCount(); i++) &#123;</span><br><span class="line">        result.put(cursor.getFieldName(i).toLowerCase(), row.get(i));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 执行kv操作</span></span><br><span class="line">IgniteCache&lt;Integer, Person&gt; cache = igniteEngine.getOrCreateCacheByCacheName(<span class="string">"person"</span>);</span><br><span class="line">Person person = cache.get(<span class="number">1</span>);</span><br><span class="line">person.setName(<span class="string">"hhbbz"</span>);</span><br><span class="line">cache.put(person);</span><br><span class="line"></span><br><span class="line"><span class="comment">//执行insert/update语句</span></span><br><span class="line">IgniteCache&lt;String, Map&lt;String, Object&gt;&gt; cache = igniteEngine.getOrCreateCacheByCacheName(<span class="string">"person"</span>));</span><br><span class="line"><span class="comment">//执行sql</span></span><br><span class="line">cache.query(<span class="keyword">new</span> SqlFieldsQuery(builder.toString()).setSchema(<span class="string">"public"</span>)).getAll();</span><br></pre></td></tr></table></figure></p>
<h1>后写缓存持久化的坑</h1>
<h2>后写缓存是什么</h2>
<p>在一个简单的通写模式中每个缓存的put和remove操作都会涉及一个持久化存储的请求，因此整个缓存更新的持续时间可能是相对比较长的。另外，密集的缓存更新频率也会导致非常高的存储负载。</p>
<p>对于这种情况，Ignite提供了一个选项来执行异步化的持久化存储更新，也叫做后写，这个方式的主要概念是累加更新操作然后作为一个批量操作异步化地刷入持久化存储中。真实的数据持久化可以被基于时间的事件触发（数据输入的最大时间受到队列的限制），也可以被队列的大小触发（当队列大小达到一个限值），或者通过两者的组合触发，这时任何事件都会触发刷新。</p>
<blockquote>
<p>更新顺序</p>
</blockquote>
<blockquote>
<p>对于后写的方式只有数据的最后一次更新会被写入底层存储。如果键为key1的缓存数据分别依次地更新为值value1、value2和value3，那么只有(key1,value3)对这一个存储请求会被传播到持久化存储。</p>
</blockquote>
<blockquote>
<p>更新性能</p>
</blockquote>
<blockquote>
<p>批量的存储操作通常比按顺序的单一存储操作更有效率，因此可以通过开启后写模式的批量操作来利用这个特性。简单类型（put和remove）的简单顺序更新操作可以被组合成一个批量操作。比如，连续地往缓存中加入(key1,value1),(key2,value2),(key3,value3)可以通过一个单一的CacheStore.putAll(...)操作批量处理。</p>
</blockquote>
<h2>这也是我遇到的第四个坑：</h2>
<p>交代一下背景：</p>
<p>我整个项目中全部使用sql去对ignite进行缓存操作。当我使用CacheJdbcPojoStoreFactory做第三方存储持久化的时候，在大批量数据操作时，持久化总是会卡顿，很慢，并且会阻塞正常的内存操作。
虽然官方文档说后写缓存是异步化的持久化存储更新，但是我也没懂为什么会阻塞我正常的内存操作。</p>
<p>于是研究了几天后，经过各种猜测和反复实践，笔者所猜测的原因是：</p>
<blockquote>
<p>在持久化过程中，涉及到更新操作时候，ignite会在第三方存储表中先进行select，再进行update，这样的话，在大批量数据操作时，会造成大量的数据库死锁从而导致性能下降，使得阻塞持久化过程，这是异步持久化的阻塞。</p>
</blockquote>
<p>那么为什么会阻塞正常的内存操作的？</p>
<p>笔者所猜测的原因是：</p>
<blockquote>
<p>当上一次持久化的数据还没全部插入到库表中时，就会阻塞ignite的内存操作了。举个例子就是，比如上一轮持久化的数据中，有“19岁”这个数据，这时候“19岁”这一条数据只存在内存中，还没保存到库表里，因为后写是批量的，假如我后写的batchsize是1000，那么这时候就已经构造好了1000条数据的批量insert/update语句，如果刚好“19岁”这条数据就在这1000条构造好update语句的数据里面，此时又在内存中把“19岁”update成“20岁”，并且再次触发持久化，那就得等待后写的批量轮询逻辑把“19岁”这个数据持久化到库表中为止，也因为这样，刚好就能解释为什么有些持久化update很快，有些却会卡住，都是取决于持久化update的那条数据是不是处于后写的batchsize的批量数据中。</p>
</blockquote>
<p>当然也可能是上面说的更新顺序的原因。</p>
<h1>总结</h1>
<p>总的来说，我是对ignite的持久化不太满意的，也有可能是因为我实践不当吧，如果有什么错误的操作或者判断，欢迎邮箱指正。</p>

      
    </div>

    

    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/blog/images/wechat.png" alt="hhbbz 微信支付"/>
        <p>微信支付</p>
      </div>
    

    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Java/" rel="tag"># Java</a>
          
            <a href="/blog/tags/Ignite/" rel="tag"># Ignite</a>
          
            <a href="/blog/tags/分布式/" rel="tag"># 分布式</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2019/03/31/jdbcTemplate高效率获取表结构，数据库元数据信息/" rel="next" title="jdbcTemplate高效率获取表结构，数据库元数据信息">
                <i class="fa fa-chevron-left"></i> jdbcTemplate高效率获取表结构，数据库元数据信息
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/07/13/ignite踩坑录-2-节点集群/" rel="prev" title="ignite实践踩坑录(2) 节点集群">
                ignite实践踩坑录(2) 节点集群 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/TOM.jpg"
                alt="hhbbz" />
            
              <p class="site-author-name" itemprop="name">hhbbz</p>
              <p class="site-description motion-element" itemprop="description">摘抄和记录的地方</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/blog/archives/">
                
                    <span class="site-state-item-count">42</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/blog/categories/index.html">
                    
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">2</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/blog/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">15</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/hhbbz" target="_blank" title="GitHub" rel="external nofollow"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:hhbbz@outlook.com" target="_blank" title="E-Mail" rel="external nofollow"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://coding.net/u/hhbbz" target="_blank" title="Coding" rel="external nofollow"><i class="fa fa-fw fa-github-alt"></i>Coding</a>
                  
                </span>
              
            </div>
          

          
          

          
          

          
            
          
          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">hhbbz</span>

  

  
</div>


  



  <div class="powered-by">Power By HEXO</div>








        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv" title="总访客量">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="site-pv" title="总访问量">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=6.3.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=6.3.0"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=6.3.0"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=6.3.0"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=6.3.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=6.3.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=6.3.0"></script>



  



	





  





  








  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  
  
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(function (item) {
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'DcsJEQ0LBt3NnDvMcJ8cJwry-gzGzoHsz',
        appKey: 'HSCBfA4q42WQQovBbS25Yp3A',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  
  

  


  
  

  

  

  

  

  

</body>
</html>
